﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:control="clr-namespace:for7raid.Control"
                    xmlns:local="clr-namespace:for7raid.vkPlayer"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    >

    <RadialGradientBrush RadiusX="1" RadiusY="5" GradientOrigin="0.5,0.3" x:Key="HighlightBackground">
        <GradientStop Color="White" Offset="0" />
        <GradientStop Color="Silver" Offset="1" />
    </RadialGradientBrush>

    <RadialGradientBrush RadiusX="1" RadiusY="5" GradientOrigin="0.5,0.3" x:Key="PressedBackground">
        <GradientStop Color="White" Offset="0" />
        <GradientStop Color="Silver" Offset=".4" />
    </RadialGradientBrush>


    <SolidColorBrush Color="Transparent" x:Key="DefaultBackground"></SolidColorBrush>
    <SolidColorBrush Color="Gray" x:Key="DisabledBackground"></SolidColorBrush>

    <RadialGradientBrush RadiusX="1" RadiusY="5" GradientOrigin="0.5,0.3" x:Key="Border">
        <GradientStop Color="White" Offset="0" />
        <GradientStop Color="Silver" Offset="1" />
    </RadialGradientBrush>


    <ControlTemplate x:Key="GradientButtonTemplate" TargetType="{x:Type Button}">
        <Border Name="Border" BorderBrush="{StaticResource Border}" BorderThickness="2" CornerRadius="2"
            Background="{StaticResource DefaultBackground}" TextBlock.Foreground="Black">

            <ContentPresenter Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" 
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"></ContentPresenter>
            </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource HighlightBackground}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBackground}" />
            </Trigger>

            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackground}"></Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="ToggleButtonTemplate" TargetType="{x:Type ToggleButton}">
        <Border Name="Border" BorderBrush="{StaticResource Border}" BorderThickness="2" CornerRadius="2"
            Background="{StaticResource DefaultBackground}" TextBlock.Foreground="Black">
            <Grid>
                <ContentPresenter Margin="{TemplateBinding Padding}" RecognizesAccessKey="True"></ContentPresenter>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource HighlightBackground}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBackground}" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBackground}" />
            </Trigger>

            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackground}"></Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="VolumeButtonTemplate" TargetType="{x:Type Button}">
        <Grid>
            <Popup Name="popup" Placement="Top" AllowsTransparency="True" PopupAnimation="Slide">
                <Border Background="{StaticResource HighlightBackground}">
                    <Slider Value="{Binding MediaElement.Volume}" Maximum="1" SmallChange="0.05" LargeChange="0.05"
                    Orientation="Vertical" Height="50">
                        
                        <i:Interaction.Behaviors>
                            <control:SliderMouseBehavior/>
                        </i:Interaction.Behaviors>
                    </Slider>
                </Border>
               
            </Popup>
            
            <Border Name="Border" BorderBrush="{StaticResource Border}" BorderThickness="2" CornerRadius="2"
            Background="{StaticResource DefaultBackground}" TextBlock.Foreground="Black">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseWheel">
                        <control:CommandAction Command="local:PlayerViewModel.VolumeMouseCommand"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Image Name="image" Source="../Icons/speaker.png" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource HighlightBackground}" />
                <Setter TargetName="popup" Property="IsOpen" Value="true" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBackground}" />
            </Trigger>

            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackground}"></Setter>
            </Trigger>

            <DataTrigger Binding="{Binding MediaElement.Volume}" Value="0">
                <Setter TargetName="image" Property="Source" Value="../Icons/speaker-mute.png"></Setter>
            </DataTrigger>
            
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type Button}">
        <Setter Property="Control.Template" Value="{StaticResource GradientButtonTemplate}"></Setter>
    </Style>

    <Style x:Key="VolumeButton" TargetType="{x:Type Button}">
        <Setter Property="Control.Template" Value="{StaticResource VolumeButtonTemplate}"></Setter>
    </Style>

    <Style TargetType="{x:Type ToggleButton}">
        <Setter Property="Control.Template" Value="{StaticResource ToggleButtonTemplate}"></Setter>
    </Style>
</ResourceDictionary>